package saii.modelo.dao;

import java.sql.SQLException;
import java.util.Collection;
import saii.integracion.wrapper.fd1.IWrapperFD1;
import saii.integracion.wrapper.fd1.WrapperFD1;
import saii.integracion.wrapper.fd1.IAsignaturaFD1;
import saii.integracion.wrapper.fd2.IWrapperFD2;
import saii.integracion.wrapper.fd2.WrapperFD2;
import saii.integracion.wrapper.fd2.IAsignaturaFD2;
import saii.integracion.wrapper.fd3.IWrapperFD3;
import saii.integracion.wrapper.fd3.WrapperFD3;
import saii.integracion.wrapper.fd3.IAsignaturaFD3;
import saii.integracion.wrapper.fd4.IWrapperFD4;
import saii.integracion.wrapper.fd4.WrapperFD4;
import saii.integracion.wrapper.fd4.IAsignaturaFD4;
import saii.modelo.IAsignatura;
import saii.modelo.impl.Asignatura;
import saii.modelo.IConvocatoria;
import saii.modelo.impl.Convocatoria;

	
public class AsignaturaDAOImpl implements IAsignaturaDAO {
	
	private IWrapperFD1 wrapperFD1;
	private IWrapperFD2 wrapperFD2;
	private IWrapperFD3 wrapperFD3;
	private IWrapperFD4 wrapperFD4;

	public AsignaturaDAOImpl(){
		try {
			wrapperFD1 = new WrapperFD1();
			wrapperFD2 = new WrapperFD2();
			wrapperFD3 = new WrapperFD3();
			wrapperFD4 = new WrapperFD4();
		} catch (SQLException ex) {
			   System.out.println("SQLException: " + ex.getMessage());
	           System.out.println("SQLState: " + ex.getSQLState());
	           System.out.println("VendorError: " + ex.getErrorCode());
		}
	}
	
	@Override
	public Convocatoria getConvocatoria(String idAsig, int year,int numConvocatoria) {
		return null;
	}

	@Override
	public Collection<IConvocatoria> getConvocatorias(String idAsig) {
		return null;
	}

	@Override
	public IAsignatura getAsignaturaById(String idAsig) {

		Asignatura asignaturaResult = new Asignatura();
		IAsignaturaFD1 asignaturaFD1 = getWrapperFD1().getAsignaturaFD1(idAsig);
		IAsignaturaFD2 asignaturaFD2 = getWrapperFD2().getAsignaturaFD2ById(idAsig);
		IAsignaturaFD3 asignaturaFD3 = getWrapperFD3().getAsignaturaFD3ById(idAsig);
		IAsignaturaFD4 asignaturaFD4 = getWrapperFD4().getAsignaturaFD4(idAsig);
		
		if(asignaturaFD1 != null){
			if(asignaturaFD1.getCodAsignatura() != null){
				asignaturaResult.setIdAsignatura(asignaturaFD1.getCodAsignatura());
			}
			if(asignaturaFD1.getNombre() != null){
				asignaturaResult.setNombre(asignaturaFD1.getNombre());
			}
//			if(asignaturaFD1.getPlanDeEstudios() != null){
			if(asignaturaFD1.getCodPlan() != null){
				asignaturaResult.setPlanDeEstudios(asignaturaFD1.getCodPlan());
			}
		}
		if(asignaturaFD2 != null){
			if(asignaturaResult.getIdAsignatura() == null && asignaturaFD2.getIdAsig() != null){
				asignaturaResult.setIdAsignatura(asignaturaFD2.getIdAsig());
			}
			if(asignaturaResult.getNombre() == null && asignaturaFD2.getNombre() != null){
				asignaturaResult.setNombre(asignaturaFD2.getNombre());
			}
			if(asignaturaResult.getPlanDeEstudios() == null && asignaturaFD2.getPlanEstudios() != null){
				asignaturaResult.setPlanDeEstudios(asignaturaFD2.getPlanEstudios());
			}
			if(true/*asignaturaFD2.getNumHoras() != 0*/){
				asignaturaResult.setNumHoras(asignaturaFD2.getNumHoras());
			}
			
			//asignaturaFD2.getProfesores()
			//asignaturaFD2.getProfesoresResponsables()
			//asignaturaResult.setNumHoras(asignaturaFD2.getNumHoras());
		}
		if(asignaturaFD3 != null){
			if(asignaturaResult.getIdAsignatura() == null && asignaturaFD3.getCodAsig() != null){
				asignaturaResult.setIdAsignatura(asignaturaFD3.getCodAsig());
			}
			if(asignaturaResult.getNombre() == null && asignaturaFD3.getNombre() != null){
				asignaturaResult.setNombre(asignaturaFD3.getNombre());
			}
		}
		if(asignaturaFD4 != null){
			if(asignaturaResult.getIdAsignatura() == null && asignaturaFD4.getCodAsignatura()!= null){
				asignaturaResult.setIdAsignatura(asignaturaFD4.getCodAsignatura());
			}
			if(asignaturaResult.getNombre() == null && asignaturaFD4.getNombre() != null){
				asignaturaResult.setNombre(asignaturaFD4.getNombre());
			}
			if(asignaturaResult.getPlanDeEstudios() == null && asignaturaFD4.getPlanDeEstudios() != null){
				asignaturaResult.setPlanDeEstudios(asignaturaFD4.getPlanDeEstudios());
			}
		}
		asignaturaResult.setCurso(0);
		asignaturaResult.setRatioRepetidores(0);
		asignaturaResult.setTipoAsignatura(null);
		
		return asignaturaResult;
	}

	@Override
	public Collection<IAsignatura> getAsignaturasByPlan(String idPlan) {
		return null;
	}

	/**
	 * @return the wrapperFD1
	 */
	public IWrapperFD1 getWrapperFD1() {
		return wrapperFD1;
	}

	/**
	 * @param wrapperFD1 the wrapperFD1 to set
	 */
	public void setWrapperFD1(IWrapperFD1 wrapperFD1) {
		this.wrapperFD1 = wrapperFD1;
	}

	/**
	 * @return the wrapperFD2
	 */
	public IWrapperFD2 getWrapperFD2() {
		return wrapperFD2;
	}

	/**
	 * @param wrapperFD2 the wrapperFD2 to set
	 */
	public void setWrapperFD2(IWrapperFD2 wrapperFD2) {
		this.wrapperFD2 = wrapperFD2;
	}

	/**
	 * @return the wrapperFD3
	 */
	public IWrapperFD3 getWrapperFD3() {
		return wrapperFD3;
	}

	/**
	 * @param wrapperFD3 the wrapperFD3 to set
	 */
	public void setWrapperFD3(IWrapperFD3 wrapperFD3) {
		this.wrapperFD3 = wrapperFD3;
	}

	/**
	 * @return the wrapperFD4
	 */
	public IWrapperFD4 getWrapperFD4() {
		return wrapperFD4;
	}

	/**
	 * @param wrapperFD4 the wrapperFD4 to set
	 */
	public void setWrapperFD4(IWrapperFD4 wrapperFD4) {
		this.wrapperFD4 = wrapperFD4;
	}

}
